import {
  findAllLearningPhase,
  gradeList,
  subjectList,
  versionsList,
  volumesList
} from '@/api/basic'
export default {
  data() {
    return {
      learningPhaseId: '',
      stages: [],
      grades: [],
      subjects: [],
      versions: [],
      volumes: [],
      params: {
        learningPhaseId: '', // 学段ID
        courseGradeId: '', // 年级ID
        courseSubjectId: '', // 学科ID
        courseVersionId: '', // 版本ID
        courseVolumeId: '' // 册别ID
      }
    }
  },
  created() {
    this.getDatas()
  },
  watch: {
    params: {
      handler() {
        this.param_query()
      },
      deep: true// 深度监听，同时也可监听到param参数变化
    }
  },
  methods: {
    getDatas() {
      this.findAllLearningPhase()
      // this.getFirstOtion(this.datas[0])
    },
    findAllLearningPhase() { // 查询学段列表
      findAllLearningPhase().then(response => {
        this.stages = response.data
        this.learningPhaseId = response.data[0].id
        this.changePhase()
        this.param_query()
      })
    },
    changePhase() { // 点击学段
      this.learningPhaseId = this.params.learningPhaseId
      this.gradeList()
      this.subjectList()
      this.versionsList()
      this.volumesList()
      this.resetBasic()
    },
    gradeList() { // 查询年级列表
      gradeList(this.learningPhaseId).then(response => {
        this.grades = response.data
      })
    },
    subjectList() { // 查询学科集合
      subjectList(this.learningPhaseId).then(response => {
        this.subjects = response.data
      })
    },
    versionsList() { // 查询版本集合
      versionsList(this.learningPhaseId).then(response => {
        this.versions = response.data
      })
    },
    volumesList() { // 查询册别集合
      volumesList(this.learningPhaseId).then(response => {
        this.volumes = response.data
      })
    },
    param_query() {
      this.$router.push({
        path: this.$route.path,
        query: {
          learningPhaseId: this.params.learningPhaseId,
          courseGradeId: this.params.courseGradeId,
          courseSubjectId: this.params.courseSubjectId,
          courseVersionId: this.params.courseVersionId,
          courseVolumeId: this.params.courseVolumeId
        }
      })
    },
    resetBasic() { // 重置基础信息
      this.params.courseGradeId = ''
      this.params.courseSubjectId = ''
      this.params.courseVersionId = ''
      this.params.courseVolumeId = ''
    }
  }
}
